
#include "executor.hpp"

#include <cstdio>

Forte::Executor::Executor(ExecutionListener& listener)
  : mListener(listener)
{}

void Forte::Executor::Execute(char const* command)
{
  char buffer[512];
  sprintf(buffer, "%s 2>&1", command);
  FILE* fd = popen(buffer, "r");
  char const* line;
  std::size_t length;
  while ((line = fgetln(fd, &length)))
  {
    mListener.OnExecutionOutput(line, length-1); // length includes newline
  }
  fclose(fd);
}

